package com.guyaning.deyson_core.core.delegates.web;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.guyaning.deyson_core.core.delegates.web.chromeclient.WebChromeClientImpl;
import com.guyaning.deyson_core.core.delegates.web.client.WebViewClientImpl;
import com.guyaning.deyson_core.core.delegates.web.route.RouteKeys;
import com.guyaning.deyson_core.core.delegates.web.route.Router;

/**
 * Created by Administrator on 2018/7/3.
 */

public class WebDelegateImpl extends WebDelegate {

    public static WebDelegateImpl create(String url) {
        Bundle arg = new Bundle();
        arg.putString(RouteKeys.URL.name(), url);
        WebDelegateImpl webDelegate = new WebDelegateImpl();
        webDelegate.setArguments(arg);
        return webDelegate;
    }


    @Override
    public Object setLayout() {
        return getWebView();
    }

    @Override
    public void onBindView(@Nullable Bundle savedInstanceState, @NonNull View rootView) {
        if (getWebUrl() != null) {
            //模拟原生的实现web跳转并加载

            Router.getInstance().loadPage(this, getWebUrl());

        }
    }

    @Override
    public IWebviewInilalizer setInilalizer() {
        return this;
    }

    @Override
    public WebView initWebView(WebView webView) {
        return new WebviewInilalizer().createWebView(webView);
    }

    @Override
    public WebViewClient initWebViewClient() {
        WebViewClientImpl client = new WebViewClientImpl(this);
        return client;
    }

    @Override
    public WebChromeClient initWebChromeClient() {
        return new WebChromeClientImpl();
    }
}
